package org.smile.homework02.hyl;

import lombok.Data;

@Data
public class ParkingSpace implements Generator {
    //1.0生成停车位
    public ParkingSpace() {
        this.number = serialNumber++;
        this.type = generateType(); //生成随机类型
    }

    private static Integer serialNumber = 1;
    //1.1停车位编号
    private Integer number;  //null
    //1.2停车位类型
    private String type;     //null
    //1.3是否被占用
    private boolean isOccupied;   //false
    //1.4显示占用车辆信息
    private Vehicle vehicle;

    public void show() {
        if (isOccupied) {
            System.out.format("%s号停车位：[是否被占用: %s, 车位类型：%s, 车牌号： %s]\n", this.getNumber(), this.isOccupied(), this.getType(), this.getVehicle().getNumber());
        } else {
            System.out.format("%s号停车位：[是否被占用: %s, 车位类型：%s]\n", this.getNumber(), this.isOccupied(), this.getType());
        }

    }

    public void describe() {
        System.out.format("%s : [number : %d, type : %s]\n", this.getClass().getSimpleName(), this.number, this.type);
    }//格式化输出

    //2 处理状态，处理车位置状态的变化，
    public void handleInParkingSpace(Vehicle vehicle) {
        setVehicle(vehicle);
        setOccupied(true);
    }

    public void handleOutParkingSpace() {
        setVehicle(null);
        setOccupied(false);
    }

}
